﻿using System;
using System.Web;

namespace Altairis.IisNetDiag {
    public class ToolsHandlerFactory : IHttpHandlerFactory {
        private const string OP_KEY = "operation";
        private const string OP_PING = "ping";
        private const string OP_TRACEROUTE = "traceroute";

        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated) {
            if (OP_PING.Equals(context.Request.QueryString[OP_KEY], StringComparison.OrdinalIgnoreCase)) {
                // Ping
                return new PingHandler();
            }
            else if (OP_TRACEROUTE.Equals(context.Request.QueryString[OP_KEY], StringComparison.OrdinalIgnoreCase)) {
                // TraceRoute
                return new TraceRouteHandler();
            }
            else {
                // Unknown - display form
                return new FormHandler();
            }
        }

        public void ReleaseHandler(IHttpHandler handler) {
            // NOOP
        }

    }
}
